%
% Author: Vasyl Mykhalchuk
%
%========================================================================

function [vertexList,faceList,vertexColorList ] = prepareMeshForExport(geometryInfo, topologyInfo, colorInfo,anmFileName)
dim = size(topologyInfo);
nF = dim(1);
[dim1,dim2,nV] = size(geometryInfo);
nV=nV/3;

%If color info is empty, then construct default one with (255,255,255)
if colorInfo == 0
    colorInfo = zeros(nV,3);
    for i=1:nV
        rA = rand(1:3);
        colorInfo(i,1) = int32(rA(1)*255);
        colorInfo(i,2) = int32(rA(2)*255);
        colorInfo(i,3) = int32(rA(3)*255);
    end%for
end%if
vertexColorList=colorInfo;

%Construct face list
faceList = zeros(nF, 3);
for i = 1:nF
    faceList(i,1)=3;
    for j=1:3
        faceList(i,j+1)=topologyInfo(i,j);
    end
end%for

%Construct vertexList
vertexList=zeros(nV,3);
nV = nV - 1;
for i=0:nV
    for j=1:3
        vertexList(i+1,j) = geometryInfo(1,1,3*i+j);
    end%for
end%for

anmFileName = strcat('../../target/', anmFileName);
exportFilePath = strcat(anmFileName, datestr(now, '_mm-dd-yy_HH-MM'));
exportFilePath = strcat(exportFilePath, '.ply');
exportPLY(exportFilePath, vertexList, vertexColorList, faceList);


end%function prepareMeshForExport